#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
#include <sys/syscall.h>
//#ifndef CLOCK_MONOTONIC
//#define CLOCK_MONOTONIC     1
//#endif

int get_mono_timetic(struct timespec* ts)
{
    if(syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts)) {
        return -1;
    }

    return 0;
}


int get_timetic()
{
    struct timespec ts;
    struct timeval tv;
    int ret = get_mono_timetic(&ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "syscall", ts.tv_sec, ts.tv_nsec);


    ret = clock_gettime(CLOCK_MONOTONIC, &ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "CLOCK_MONOTONIC", ts.tv_sec, ts.tv_nsec);
#if 0
    ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "CLOCK_MONOTONIC_RAW", ts.tv_sec, ts.tv_nsec);
#endif
    ret = clock_gettime(CLOCK_REALTIME, &ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "CLOCK_REALTIME", ts.tv_sec, ts.tv_nsec);

    ret = gettimeofday(&tv, NULL);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "gettimeofday", tv.tv_sec, tv.tv_usec);

    ret = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "CLOCK_PROCESS_CPUTIME_ID", ts.tv_sec, ts.tv_nsec);

    ret = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
    assert(0 == ret);
    printf("%29s => %lu:%9ld\n", "CLOCK_THREAD_CPUTIME_ID", ts.tv_sec, ts.tv_nsec);
       
    return 0;
}


int main()
{
    get_timetic();

    sleep(10);
    system("ntpdate pool.ntp.org");

    get_timetic();
    
    return 0;
}
